Github: The beginning

Brock Kamrath

1/18/2021

Introduction

Welcome to Version Control week!

Today’s Schedule

Discussion

You were asked to read

*What were your takeaways from the Bryan article?

*What were your takeaways from the Stewart Lowndes article?

Discussion Questions

1. What the difference between Git and Github?

Discussion Questions

  1. What the difference between Git and Github?

2. In the Our path… article, the authors discuss the implementation of version control/reproducibility (via Github and RStudio) in the global OHI assessment. How do you see version control/reproducability being implemented in your research?

Discussion Questions

  1. What the difference between Git and Github?

  2. In the Our path… article, the authors discuss the implementation of version control/reproducibility (via Github and RStudio) in the global OHI assessment. How do you see version control/reproducability being implemented in your research?

3. What do you think will be the largest obstacle to utilizing version control with GitHub?

Happy Git and GitHub for the useR

To start today’s lecture

You can interact with Git from the Terminal/Shell

You can launch a shell from RStudio. This is often handy, because RStudio makes every effort to put you in a same working directory, i.e. in the current project.

Basic Shell Commands

Chapter 12: Connect RStudio to Git and GitHub

Objectives:

  1. Make sure that you can all pull from and push to GitHub in RStudio on your local computer
  2. Use RStudio to edit, commit, and push to your remote GitHub repo

Order of operation

  1. Connect to GitHub
  2. Make a repository (or repo) on GitHub
  3. Clone the repo to your local computer via RStudio
  4. Make a local change, commit, and push
  5. Confirm local change propagated to the GitHub remote
  6. Clean up

Connect to GitHub

Homepage should look like this

Homepage should look like this

Make a repo on GitHub

Click the plus, then the “New repository” button.

Make a repo on GitHub

  • How to fill this in:
    • Repository name: myrepo (or whatever you wish, we’ll delete this soon anyway).
    • Description: “testing my setup” (or whatever, but some text is good for the README).
    • Public.
    • YES Initialize this repository with a README.
  • For everything else, just accept the default.
  • Click big green button “Create repository.”

Make a repo on GitHub

You should see this

You should see this

Clone the repo to your local computer

Copy the HTTPS clone URL to your clipboard via the green “Clone or Download” button.

Clone the new GitHub repo to your local computer via RStudio

  • Start a new Project in RStudio
    • File > New Project > Version Control > Git.
    • In the “repository URL” paste the URL of your new GitHub repository.
      • https://github.com/bjkamrat/myrepo.git
  • Be intentional about where you create this Project.
  • Check "Open in new session
  • Click “Create Project” to create a new directory, which will be:
    • a directory or “folder” on your computer
    • a Git repository, linked to a remote GitHub repository
    • an RStudio Project

Make a local change, commit, and push

In your local RStudio Project modify the README.md file + Add the line “This is a line from RStudio” + Save your change

Now, commit these changes to your local repo. How?

In RStudio:

Pull then Push your local changes online to GitHub

Already up to date.
[master dc671f0] blah
 3 files changed, 22 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 myrepo.Rproj

Workflow

Do work somewhere. Commit it. Push it or pull it* depending on where you did it, but get local and remote “synced up”. Repeat.

* Note that in general (and especially in future when collaborating with other developers) you will usually need to pull changes from the remote (GitHub) before pushing the local changes you have made. For this reason, it’s a good idea to try and get into the habit of pulling before you attempt to push.

Confirm local change propgated to GitHub

  1. Go back to the browser. I assume we’re still viewing your new GitHub repo.

  2. Refresh.

  3. You should see the new “This is a line from RStudio” in the README.

  4. If you click on “commits,” you should see one with the message “Commit from Rstudio”

Clean up

Local * When you’re ready to clean up, you can delete the local repo any way you like. It’s just a regular directory on your computer.

GitHub * In the browser, go to your repo’s landing page on GitHub. Click on “Settings”. * Scroll down, click on “delete repository,” and do as it asks.

Before moving on, lets discuss some of the Git methodology/terminology

Git methodology/terminology

Git methodology/terminology

These snapshots act as version control

Git methodology/terminology

These snapshots act as version control

Git methodology/terminology

These snapshots act as version control

Git methodology/terminology

Git methodology/terminology

Git methodology/terminology

Git methodology/terminology

Git methodology/terminology

Summary

repo - your project folder

commit - snapshot of repo

checkout - time travel to specific commit

branch - a moveable label that point to a commit

merge - combining two branches

remote - a computer/server with the repository on it

clone - the first time you get the repo from the remote

push - send commits (with comments) to a remote

pull - get updated repo from a remote

Now, lets use GitHub and RStudio together (Chapter 15)

Start by making a repo in GitHub

From here

For Thursday (2/4/21), you need to